package com.holly.common.utils;

import java.util.List;

/**
 * 2016/12/14 <br/>
 *
 * @author Joey Huang QQ:273179370）
 */

public class ToArrayUtils {

    public static <ResultType,PreType> ResultType[] toArray(List<PreType> list, Adapter<ResultType,PreType> adapter) {
        if (list == null || list.size() == 0) {
            return null;
        }
        Object[] result = new Object[list.size()];
        for (int i = 0; i < result.length; i++) {
            result[i] = adapter.get(list.get(i));
        }
        return (ResultType[]) result;
    }

    public interface Adapter<ResultType,PreType> {
        ResultType get(PreType preType);
    }
}
